﻿<?
	class TemplatesFactory{
		private $template_name = '';
		private $template_filename = '';
		private $template_path = '';
		private $template_data = '';
		private $template_iterator = 0;
		
		public function LoadTemplate($Template, $Vars){
			$this->template_name = $Template;
			$this->template_filename = $Template . '.php';
			$this->template_path = PUBLIC_TEMPLATES_DIRECTORY . $this->template_filename;
			if (!file_exists($this->template_path)) return;
			
			$this->template_iterator = 0;
			
			$TemplatesFactory = $this;

			ob_start();
			
			$tmp = '';
			
			foreach ($Vars as $Data){
				require($this->template_path);
				$tmp .= ob_get_contents();
				ob_clean();
				
				$this->template_iterator++;
			}
			ob_end_flush();
			echo $tmp;
		}
		
		public function IsCurrentIteration($Number){ return $this->template_iterator == $Number; }
		public function GetCurrentIteration(){ return $this->template_iterator; }
		public function EvalFunction($Function){ return $Function($this); }
		
	}
?>